<?php
namespace Home\Controller;
use Think\Controller;
class PublicController extends Controller {
	//加载登陆页面
	public function login(){
		$this -> display();
	}
	//登陆判断
	public function logincheck(){
		//获取登陆信息
		// var_dump($_SESSION);
		$name = $_POST["name"];
		$pass = $_POST["pass"];
		$user = M("qtuser")->where("name = '$name' and pass = '$pass'")->select();
		if(!empty($user)){
			session('name',$name);
			$this -> redirect("Home/Index/index");
			
		}else{
			$this -> redirect("Home/public/login");
			
		}
	}
	public function register(){
		$this->display();
	}
	public function registerAction(){
		$name=$_POST['name'];
		$code=$_POST['code'];
		$pass = $_POST['pass'];
		$qrpass = $_POST['qrpass'];
		if(!empty($_POST) && $pass = $qrpass && $this -> check_verify($code)){
			session('name',$name);
			$user = M("qtuser")->add($_POST);
			$this -> redirect("Home/Index/index");
		}else{
			$this -> redirect("Home/Public/register");
		}
	}
	function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}
	public function yzm(){
		$Verify =  new \Think\Verify();
		$Verify->fontSize = 30;
		$Verify->length   = 3;
		$Verify->useNoise = false;
		$Verify->entry();
	}
	//退出登录
	public function loginout(){
		
        session('name',null);
		
        $this->success('退出成功',U('Index/index'));
    }
	
}